//
//  JSLCoopertionController.m
//  JingleSpeedLoan
//
//  Created by 宋志彬 on 2018/7/31.
//  Copyright © 2018年 宋质彬. All rights reserved.
//

#import "JSLCoopertionController.h"
#import "JSLSettingCell.h"

@interface JSLCoopertionController ()
<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic , strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *arrDataSource;
@end

@implementation JSLCoopertionController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"商务合作";
    [self tableView];
    
    [self baseConfig:PageGobackTypePop];
    
    
    self.tableView.tableFooterView = [JSLKitFactory jsl_viewWithFrame:CGRectZero backgroundColor:BACKGROUND_COLOR superView:nil];
    

    
    self.arrDataSource = [NSMutableArray arrayWithArray:@[
                                                          
                                                          @{
                                                              @"title" : @"联系电话",
                                                              @"flagStr" : @"lxdh",
                                                              @"sutitle" : @"13651937369"
                                                              },
                                                          @{
                                                              @"title" : @"联系邮箱",
                                                              @"flagStr" : @"lxyx",
                                                              @"sutitle" : @"xiweipeng@163.com"
                                                              }
                                                          ]];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arrDataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    JSLSettingCell *cell = [JSLSettingCell cellWithTableView:tableView];
    [cell configSettingViewData:self.arrDataSource[indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *info = self.arrDataSource[indexPath.row];
    NSString * flagStr = self.arrDataSource[indexPath.row][@"flagStr"];
    
    if ([flagStr isEqualToString:@"lxdh"]) {
        [self talTapping:info[@"sutitle"]];
    }else if ([flagStr isEqualToString:@"lxyx"]){
        [[UIApplication sharedApplication]openURL:[NSURL   URLWithString:@"mailto:example@example.com"]];
    }
}
#pragma mark 客服电话
static BOOL isbusy;

- (void)talTapping:(NSString *)phone {
    if (!isbusy) {
        isbusy = YES;
        NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",phone];
        [str replaceOccurrencesOfString:@" " withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [str length])];
        //  [str replaceOccurrencesOfString:@"-" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [str length])];
        UIWebView *callWebview = [[UIWebView alloc] init];
        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
        [self.view addSubview:callWebview];
        
        dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, 3ull *NSEC_PER_SEC);
        dispatch_after(time, dispatch_get_main_queue(), ^{
            //执行操作
            isbusy = NO;
        });
    }
}



#pragma mark - get
- (UITableView *)tableView{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height-64 -49 ) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
        _tableView.scrollEnabled = YES;
        _tableView.rowHeight = 50*AutoSizeScaleYY;
        _tableView.backgroundColor = BACKGROUND_COLOR;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        [self.view addSubview:_tableView];
        
        _tableView.tableHeaderView = [JSLKitFactory jsl_viewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10*AutoSizeScaleYY) backgroundColor:BACKGROUND_COLOR superView:nil];
        
    }
    
    return _tableView;
}
/*
 #pragma mark - Navigation


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
